//
//  fajianxqViewController.m
//  BAOASystem
//
//  Created by michael on 2018/2/23.
//  Copyright © 2018年 czd. All rights reserved.
//

#import "fajianxqViewController.h"

@interface fajianxqViewController ()

@end

@implementation fajianxqViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:

[UIColor whiteColor],NSForegroundColorAttributeName, nil];
 
[self.navigationController.navigationBar setTitleTextAttributes:attributes];
 self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"0a62ea"];
 self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
 self.view.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
    // Do any additional setup after loading the view.
    [self loaddata];
  
}
- (void)loaddata{
NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];

   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
NSString *bodyStr = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>%@</userName><password>%@</password><website>%@</website><language>%@</language><type>%@</type></header><body><toMemberCompanyId>%@</toMemberCompanyId><toMemberNameId>%@</toMemberNameId><productId>%@</productId></body></message>",userName,password,website,language,BAtype,_toMemberCompanyId,_toMemberNameId,_productId];
 bodyStr= [bodyStr URLEncodedString];
 NSArray * array = @[@{@"arg0":bodyStr}];
     NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bMessageList];
 [HttpTools requestWithURL:path arrays:array method:@"toSendMessage" success:^(id JSON) {
   NSLog(@"%@",JSON);
if([[NSString stringWithFormat:@"%@",JSON[@"code"]]isEqualToString:@"200"]){
_dic= JSON;
[self initview];
}else{
    [self.view makeToast:JSON[@"msg"]];

}
//[_tableView reloadData];

 } failure:^(NSError *error) {

    }];

}
- (void)initview{
if (!_tableView) {
      _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth,KScreenHeight-kTopHeight) style:UITableViewStylePlain];
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
 self.tableView.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
_tableView.bounces = NO;
_tableView.dataSource = self;
_tableView.delegate = self;
[self.view addSubview:_tableView];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row ==0){
static NSString *cellid0 = @"cell0";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid0];
     if (!cell) {
       cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid0];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
      UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(10, 10, KScreenWidth-20, 60)];
      view1.backgroundColor = [UIColor whiteColor];
      [cell.contentView addSubview:view1];
      UILabel *companyname = [[UILabel alloc]initWithFrame: CGRectMake(0, 0, view1.width, 30)];
      companyname.backgroundColor = [UIColor whiteColor];
      companyname.text = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"公司名称:", nil),_dic[@"toMemberCompany"]];
       companyname.textAlignment = 0;
         companyname.font = [UIFont systemFontOfSize:13];
    [view1 addSubview:companyname];
    UIView *view11 = [[UIView alloc]initWithFrame:CGRectMake(5, 30, view1.width-10, .5)];
    view11.backgroundColor = [UIColor colorWithHexString:@"aeaeae"];
    [view1 addSubview:view11];
     UILabel *personname = [[UILabel alloc]initWithFrame: CGRectMake(0, 30.5, view1.width, 29.5)];
      personname.backgroundColor = [UIColor whiteColor];
      personname.text = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"收件人:", nil),_dic[@"toMemberName"]];
       personname.textAlignment = 0;
         personname.font = [UIFont systemFontOfSize:13];
    [view1 addSubview:personname];
    
    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, view1.bottom+10, 80, 30)];
  label2.font = [UIFont systemFontOfSize:13];
    label2.backgroundColor = [UIColor whiteColor];
    label2.textColor = [UIColor colorWithHexString:@"484848"];
NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*主题", nil)];
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
[attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label2.attributedText = attrStr;
    [cell.contentView addSubview:label2];
    _zhutitextfield  = [[UITextField alloc]initWithFrame:CGRectMake(label2.right, label2.top, KScreenWidth-20-label2.width, 30)];
    _zhutitextfield.backgroundColor = [UIColor whiteColor];
   [_zhutitextfield setFont:[UIFont systemFontOfSize:13]];
    [cell.contentView addSubview:_zhutitextfield];
        UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(10, _zhutitextfield.bottom+10, KScreenWidth-20, 30)];
          label3.font = [UIFont systemFontOfSize:13];

    label3.backgroundColor = [UIColor whiteColor];
    label3.textColor = [UIColor colorWithHexString:@"484848"];
NSString *string3 =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*详细说明", nil)];
NSMutableAttributedString *attrStr3 = [[NSMutableAttributedString alloc] initWithString:string3];
[attrStr3 addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label3.attributedText = attrStr3;
    [cell.contentView addSubview:label3];
    _shuomingtextview = [[UITextView alloc]initWithFrame:CGRectMake(10, label3.bottom, KScreenWidth-20, 150)];
    _shuomingtextview.delegate = self;
//      [_shuomingtextview addTarget:self action:@selector(endediting) forControlEvents:UIControlEventEditingDidEnd];// 可在自定义selector处
    _shuomingtextview.backgroundColor = [UIColor whiteColor];
    [cell.contentView addSubview:_shuomingtextview];
    _label4  = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth-20,20)];
    _label4.text = NSLocalizedString(@"请填写您想了解的详细信息,如产品规格,价格,起定量等", nil);
    _label4.font = [UIFont systemFontOfSize:13];
       _label4.backgroundColor = [UIColor whiteColor];
    _label4.textColor = [UIColor colorWithHexString:@"484848"];
    [_shuomingtextview addSubview:_label4];
    
    
       }
    
return cell;
}
else{
static NSString *cellid1 = @"cell1";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid1];
     if (!cell) {
       cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid1];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
 UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 120, 30)];
  label1.font = [UIFont systemFontOfSize:13];
    label1.backgroundColor = [UIColor whiteColor];
    label1.textColor = [UIColor colorWithHexString:@"484848"];
NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*您的公司", nil)];
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
[attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label1.attributedText = attrStr;
    [cell.contentView addSubview:label1];
        _companyextfield  = [[UITextField alloc]initWithFrame:CGRectMake(label1.right, label1.top, KScreenWidth-20-label1.width, 30)];
    _companyextfield.backgroundColor = [UIColor whiteColor];
   [_companyextfield setFont:[UIFont systemFontOfSize:13]];
    [cell.contentView addSubview:_companyextfield];
    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, label1.bottom, KScreenWidth-20,30)];
    label2.text =NSLocalizedString(@"-企业用户请填写营业执照上的公司名称,个人用户请填写个人(姓名),如个人(张三).", nil);
    label2.numberOfLines = 0;
      label2.font = [UIFont systemFontOfSize:11];
    label2.textColor =[UIColor colorWithHexString:@"0aa0f6"];
    [cell.contentView addSubview:label2];
    
    UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(10, label2.bottom, 80, 30)];
  label3.font = [UIFont systemFontOfSize:13];
    label3.backgroundColor = [UIColor whiteColor];
    label3.textColor = [UIColor colorWithHexString:@"484848"];
NSString *string3 =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*您的名字", nil)];
NSMutableAttributedString *attrStr3 = [[NSMutableAttributedString alloc] initWithString:string3];
[attrStr3 addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label3.attributedText = attrStr3;
    [cell.contentView addSubview:label3];
      _nametextfield  = [[UITextField alloc]initWithFrame:CGRectMake(label3.right, label3.top, KScreenWidth-20-label3.width-100, 30)];
    _nametextfield.backgroundColor = [UIColor whiteColor];
   [_nametextfield setFont:[UIFont systemFontOfSize:13]];
    [cell.contentView addSubview:_nametextfield];
    
        _sexbox = [[jiaotongbox alloc]init];
          _sexbox = [jiaotongbox checkBoxFootView];
          _sexbox.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
 _sexbox.frame = CGRectMake(_nametextfield.right+0, _nametextfield.top, 100, 30);
        [cell.contentView addSubview:_sexbox];
        
         UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(10, label3.bottom+10, 120, 30)];
  label4.font = [UIFont systemFontOfSize:13];
    label4.backgroundColor = [UIColor whiteColor];
    label4.textColor = [UIColor colorWithHexString:@"484848"];
NSString *string4 =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*联系电话", nil)];
NSMutableAttributedString *attrStr4 = [[NSMutableAttributedString alloc] initWithString:string4];
[attrStr4 addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label4.attributedText = attrStr4;
    [cell.contentView addSubview:label4];
      _phonetextfield  = [[UITextField alloc]initWithFrame:CGRectMake(label4.right, label4.top, KScreenWidth-20-label4.width, 30)];
    _phonetextfield.backgroundColor = [UIColor whiteColor];
   [_phonetextfield setFont:[UIFont systemFontOfSize:13]];
    [cell.contentView addSubview:_phonetextfield];
    
     UILabel *label5 = [[UILabel alloc]initWithFrame:CGRectMake(10, label4.bottom+10, 80, 30)];
  label5.font = [UIFont systemFontOfSize:13];
    label5.backgroundColor = [UIColor whiteColor];
    label5.textColor = [UIColor colorWithHexString:@"484848"];
NSString *string5 =[NSString stringWithFormat:@"%@",NSLocalizedString(@"*电子邮件", nil)];
NSMutableAttributedString *attrStr5 = [[NSMutableAttributedString alloc] initWithString:string5];
[attrStr5 addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label5.attributedText = attrStr5;
    [cell.contentView addSubview:label5];
      _emailtextfield  = [[UITextField alloc]initWithFrame:CGRectMake(label5.right, label5.top, KScreenWidth-20-label5.width, 30)];
    _emailtextfield.backgroundColor = [UIColor whiteColor];
   [_emailtextfield setFont:[UIFont systemFontOfSize:13]];
    [cell.contentView addSubview:_emailtextfield];
    
          UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
      button2.frame = CGRectMake(10, _emailtextfield.bottom+10, KScreenWidth-20, 40);
          button2.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

  [button2 setTitle:NSLocalizedString(@"发送信息", nil) forState:UIControlStateNormal];
    button2.titleLabel.font = [UIFont systemFontOfSize: 14.0];
   [button2 setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
 [button2 addTarget:self action:@selector(action2) forControlEvents:UIControlEventTouchUpInside];

            [cell.contentView addSubview:button2];
         
    
       }
    
return cell;
}
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    self.label4.hidden = YES;//开始编辑时
    return YES;
}
- (void)action2{
NSString *zhutiname = [_zhutitextfield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *shuomingstr = [_shuomingtextview.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

NSString *comname = [_companyextfield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *name = [_nametextfield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *phone = [_phonetextfield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

NSString *emailname = [_emailtextfield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

 if ([zhutiname isEqualToString:@""]|| zhutiname.length == 0){
     [self.view makeToast:NSLocalizedString(@"主题为空", nil)];
} else if ([shuomingstr isEqualToString:@""]|| shuomingstr.length == 0){
     [self.view makeToast:NSLocalizedString(@"详细说明为空", nil)];
}else if ([comname isEqualToString:@""]|| comname.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-公司名称为空", nil)];
}else if ([name isEqualToString:@""]|| name.length == 0){
     [self.view makeToast:NSLocalizedString(@"名字为空", nil)];
}else if ([phone isEqualToString:@""]|| phone.length == 0){
     [self.view makeToast:NSLocalizedString(@"联系电话为空", nil)];
}else if ([emailname isEqualToString:@""]|| emailname.length == 0){
     [self.view makeToast:NSLocalizedString(@"电子邮箱为空", nil)];
}else if (![httpTool isValidateEmail:emailname]){
     [self.view makeToast:NSLocalizedString(@"注册信息-邮箱不规范", nil)];
}else{
NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];
   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];

   NSString *uid = [[NSUserDefaults standardUserDefaults] objectForKey:@"uid"];
      NSString *cpid = [[NSUserDefaults standardUserDefaults] objectForKey:@"cpid"];
      NSString *companyName = [[NSUserDefaults standardUserDefaults] objectForKey:@"companyName"];

   NSString *productId =_dic[@"productId"];
 if (productId.length>0) {
    
}else{

productId = @"";
}
NSString *bodyStr = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>%@</userName><password>%@</password><website>%@</website><language>%@</language><type>%@</type></header><body><messageinfo><toMemberCompanyId>%@</toMemberCompanyId><toMemberNameId>%@</toMemberNameId><productId>%@</productId><title>%@</title><content>%@</content><fromMemberId>%@</fromMemberId><fromCompanyId>%@</fromCompanyId><fromCompanyName>%@</fromCompanyName><fromMemberName>%@</fromMemberName><formMemberPhone>%@</formMemberPhone><formMemberEmail>%@</formMemberEmail></messageinfo></body></message>",userName,password,website,language,BAtype,_dic[@"toMemberCompanyId"],_dic[@"toMemberNameId"],productId,zhutiname,shuomingstr,uid,cpid,companyName,name,phone,emailname];
 bodyStr= [bodyStr URLEncodedString];
 NSArray * array = @[@{@"arg0":bodyStr}];
     NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bMessageList];
 [HttpTools requestWithURL:path arrays:array method:@"messageSave" success:^(id JSON) {
 if([[NSString stringWithFormat:@"%@",JSON[@"code"]]isEqualToString:@"200"]){
          [self.view makeToast:JSON[@"msg"]];

 [self performSelector: @selector(popaction) withObject: nil afterDelay:1.0f];

 
 }else{
     [self.view makeToast:JSON[@"msg"]];

 }
  

//[_tableView reloadData];
 } failure:^(NSError *error) {

    }];



}

}
- (void)popaction{
[self.navigationController popViewControllerAnimated:YES];

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 30+150+60+30+30;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
